package yxy.game.pm2.module.union.player.tech;

import java.util.ArrayList;
import java.util.Collection;

import yxy.apple.util.NumberUtility;
import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.unionskill;
import yxy.cherry.data.bean.unionskillupcost;
import yxy.cherry.data.script.fomula;
import yxy.game.pm2.bean.Currency;

public class UnionTech {
	// bean===========================================================================
	private int dataId;
	private int level;
	private int pos;

	public int getDataId() {
		return dataId;
	}

	public void setDataId(int dataId) {
		this.dataId = dataId;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getPos() {
		return pos;
	}

	public void setPos(int pos) {
		this.pos = pos;
	}

	// func===========================================================================

	public unionskill data() {
		return DataCenter.getData(getDataId(), unionskill.class);
	}

	/** 升级 */
	protected void upgrade() {
		pos++;
		if (pos >= data().getSkilltype().length) {
			pos = 0;
			level++;
		}
	}

	/** 消费 */
	public Collection<Currency> cost() {
		int skillcostId = data().getSkilltype()[getPos()];
		unionskillupcost costdata = DataCenter.getData(skillcostId, unionskillupcost.class);
		ArrayList<Currency> costs = new ArrayList<>();
		Currency cost1 = Currency.create(costdata.getCosttype1(), costdata.getBegincostid1(),
				costdata.getBegincostnum1() + costdata.getCostnum1() * getLevel());
		Currency cost2 = Currency.create(costdata.getBegincosttype2(), costdata.getBegincostid2(),
				costdata.getBegincostnum1() + costdata.getCostnum2() * getLevel());

		costs.add(cost1);
		costs.add(cost2);

		return costs;
	}

	protected Collection<Currency> resetback() {
		ArrayList<Currency> costs = new ArrayList<>();
		unionskill data = data();
		for (int i = 0; i < data.getSkilltype().length; i++) {
			int skillcostId = data().getSkilltype()[i];
			unionskillupcost costdata = DataCenter.getData(skillcostId, unionskillupcost.class);

			int return1 = fomula.联盟技能花费1返还比例.intValue();
			int return2 = fomula.联盟技能花费2返还比例.intValue();

			int num1 = NumberUtility.arithmeticSum(costdata.getBegincostnum1(), getLevel() + (getPos() > i ? 1 : 0), costdata.getCostnum1()) * return1 / 100;
			int num2 = NumberUtility.arithmeticSum(costdata.getBegincostnum2(), getLevel() + (getPos() > i ? 1 : 0), costdata.getCostnum2()) * return2 / 100;

			Currency cost1 = Currency.create(costdata.getCosttype1(), costdata.getBegincostid1(), num1);
			Currency cost2 = Currency.create(costdata.getBegincosttype2(), costdata.getBegincostid2(), num2);

			costs.add(cost1);
			costs.add(cost2);
		}

		return Currency.merge(costs);
	}

	protected void reset() {
		setLevel(0);
		setPos(0);
	}

	/** 获取加成属性 */
	protected PropertyData property() {
		PropertyData propertyData = new PropertyData();
		unionskill data = data();
		for (int i = 0; i < data.getSkilltype().length; i++) {
			PropertyType type = PropertyType.forNumber(data.getSkilltype()[i]);
			int value = data.getPromote()[i] * (getLevel() + (getPos() > i ? 1 : 0));
			propertyData.addValue(type, value);
		}

		return propertyData;
	}

}
